package com.zl.credit.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zl.credit.entity.CreditMessageParticular;
import com.zl.credit.entity.CreditProgress;
import com.zl.credit.service.CreditProgressService;
import com.zl.credit.service.impl.CreditMessageParticularServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.UUID;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author anonymous
 * @since 2020-07-14
 */
@Controller
@RequestMapping("/credit-message-particular")
public class CreditMessageParticularController {

    @Autowired
    private CreditMessageParticularServiceImpl particularService;

    @Autowired
    private CreditProgressService progressService;

    /**
     * 向个人,居住和工作信息表插一条数据
     * @param particular
     * @return
     */
    @RequestMapping(value = "/addparticular",method = RequestMethod.POST)
    public String addparticular(CreditMessageParticular particular, String name, Model model){
        //主键生成
        System.out.println("particular = " + particular + ", cpname = " + name + ", model = " + model);
        String substring = UUID.randomUUID().toString().substring(0, 6);
        particular.setCmpId(substring);
        particularService.addmessageparticular(particular);
        //更新申请进度表
        //1.查询当前用户的申请进度表
        CreditProgress progress = progressService.selectprogressstatus(name);
        System.out.println("progress:"+progress);
        //更改基本表id和
        progress.setCmpId(substring);
        //2.更新到申请进度表
        progressService.updateprogress(progress);
        model.addAttribute("name",name);
        return "apply3";
    }

    /**
     * 根据主键id查询个人，工作，居住信息
     * @param cmpId
     * @return
     */
    @RequestMapping(value = "QueryByid",method = RequestMethod.GET)
    public String QueryByid(String cmpId){
        System.out.println("cmpId = " + cmpId);
        CreditMessageParticular particular = particularService.getById(cmpId);
        System.out.println(particular);
        return "index";
    }
}
